/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package sensorgui;

import java.awt.BasicStroke;
import java.awt.Graphics;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Stroke;
import java.awt.geom.Arc2D;
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.awt.geom.Ellipse2D;

/**
 *
 * @author Conor
 */
public class SensorView{

    private Sensor sensor;
    
    private Arc2D arc1;
    Point2D centerPoint;

    public SensorView(Sensor sensor){
        this.sensor = sensor;
        centerPoint = new Point2D.Double(sensor.getX(),sensor.getY());

        arc1 = new Arc2D.Double();
        arc1.setArcByCenter(centerPoint.getX(),
                                centerPoint.getY(),
                                sensor.getWidth(),
                                sensor.getDirection().getValue(),
                                sensor.getRange(),
                                Arc2D.OPEN);
    }
    
    public boolean objectInView(double x, double y){
    	return arc1.contains(x, y);
    }

    public void paintSensor(Graphics g){

        Graphics2D g2d = (Graphics2D)g;

        g2d.setColor(Color.BLACK);

        Stroke wheelStroke = new BasicStroke(2, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);


        Line2D line1 = new Line2D.Double(centerPoint, arc1.getEndPoint());
        
        Line2D line2 = new Line2D.Double(centerPoint, arc1.getStartPoint());
        
        Ellipse2D e1lipse1 = new Ellipse2D.Double(centerPoint.getX()-5, centerPoint.getY()-5, 10, 10);
        
        g2d.fill(e1lipse1);
        g2d.setStroke(wheelStroke);
        g2d.setColor(Color.GRAY);
        
        g2d.draw(line2);
        g2d.draw(line1);
        g2d.draw(arc1);

}
}
